myApp.controller('attrController',function($scope,$state,toaster,$serAttr,$uibModal,$log) {
    var ctrl = this;
    ctrl.vm = {
        data:{},
        page:{},
        changeAttr:function(data){
            $state.go('app.changeAttr',{id:data.id,name:data.name,alias:data.alias,backend_show:data.backend_show},{reload:true});
        }
    };
    $scope.model = {
        info: {
            state: 0,
            id: '',
            name: '',
            phone: '',
            enable: false
        },
        open: function ( data) {

            var modalInstance = $uibModal.open({
                templateUrl: 'addAttrContent.html',
                controller: 'addAttrCtrl',
                windowClass: 'adminOpen',
                resolve: {
                    info: function () {
                        return $scope.model.info;
                    }
                }
            });
            modalInstance.result.then(function (res) {
                if (res) {
                    vm.init();
                }
            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });
        },
        open1: function ( data) {

            var modalInstance = $uibModal.open({
                templateUrl: 'changeAttr.html',
                controller: 'changeAttrCtrl',
                windowClass: 'adminOpen',
                resolve: {
                    info: function () {
                        return data;
                    }
                }
            });
            modalInstance.result.then(function (res) {
                if (res) {
                    vm.init();
                }
            }, function () {
                $log.info('Modal dismissed at: ' + new Date());
            });
        }
    };
    /*跳转页面*/
    $scope.pageChanged = function() {
        vm.init(ctrl.vm.page.current_page);
    };
    /*每页显示数量显示*/
    $scope.placement = {
        options: [5,10,20,50],
        pageSize:5,
        selected: 10,
        changeFn:function(){
            vm.init(0,0);
        }
    };
    var vm = {
        init:function(page){
            $serAttr.getAttrList({
                page:page||0,
                size:$scope.placement.selected
            }).then(function(res){
                if(res.code==1){
                    ctrl.vm.data = res.data;
                    if(!page||page==0){ctrl.vm.page = res.addtion_data;}
                }else{
                    toaster.info('提示',res.message);
                }
            })
        }
    };

    vm.init();
});